define([
    '../../../app/framework/base/baseView',
    '../../../app/framework/bean/ecReport'
], function (
    BaseView,
    reportBean
) {
        var self;
        var tableData = undefined;
        var pageNav = {
            tPage: 1,
            cPage: 1,
            pSize: 20,
            tSize: 1
        };

        var menus = [];
        var param = {
            "groups": ["day"],       // 分组条件，指定需要根据什么进行分组，取值范围请参考支持字段列表（必须项，且day和webSite必须进行分组）
            "filters": {
                "day": {
                    "since": moment().add("day", -1).format("YYYY-MM-DD"),
                    "until": moment().format("YYYY-MM-DD")
                },
                "webSite": [],
                "age": [],
                "gender": [],
                "device": [],
                "account": [],
                "adType": [],
                "adId": [],
                "adName": []
            },                  // 过滤条件（必须项，且day和webSite必须进行过滤），除了day以外，别的均以数组形式传递，名称和groups字段取值一致，但是ad/asSet/campaign需要拆分为
            // adId/adName/adSetId/adSetName/campaignId/campaignName，因为需要支持id和name检索
            "pSize": pageNav.pSize,        // 分页大小（必须项，正整数）
            "cPage": pageNav.cPage           // 请求第几页（必须项，从1开始）
        };
        return {
            init: function () {
                BaseView.apply(this, arguments);
                self = this;
                self.reqMenus();
                console.log("report init!");
            },
            onGroupChange: function () {

            }, initView: function () {
                //时间段选择
                $('.daterangepicker-sample1').daterangepicker({
                    "startDate": param.filters.day.since,
                    "endDate": param.filters.day.until,
                    "opens": "nxdc",
                    "alwaysShowCalendars": true,
                    locale: {
                        "applyLabel": "OK",
                        "format": "YYYY-MM-DD",
                        "cancelLabel": ''
                    },
                    autoApply: true
                }, function (start, end, label) {
                    param.filters.day.since = start.format('YYYY-MM-DD');
                    param.filters.day.until = end.format('YYYY-MM-DD');
                    param.groups.push("day");
                });

                var webSites = [];
                var acts = [];
                $.each(menus, function (index, item) {
                    var it = {
                        name: item.webSite,
                        val: item.productManageProductId
                    };
                    webSites.push(it);
                });
                //站点选择
                $("div.ndp-drop-wrapper[name=drop-webSite]").empty().drop({
                    data: webSites,
                    name: "webSite",
                    placeholder: I18N.getText("ecReport", "chooseWebSite")
                }).off("ITEM_CLICK").on("ITEM_CLICK", function (e) {
                    param.filters.webSite = [];
                    param.filters.account = [];
                    param.filters.webSite.push(e.originalEvent.data.val);
                    acts = _.where(menus, { productManageProductId: param.filters.webSite[0] })[0].fbAccounts;
                    self.rendererDropActs(acts);
                });
                //广告账号
                self.rendererDropActs(acts);
                //广告类型
                $("div.ndp-drop-wrapper[name=drop-adType]").empty().drop({
                	type: 4,
                    data: [{ id: "dpa", text: I18N.getText("ecReport", "dpa") }, ,
                        { id: "other", text: I18N.getText("ecReport", "other") }],
                    name: "adType",
                    placeholder: I18N.getText("ecReport", "chooseAdType")
                }).off("APPLY_CLICK").on("APPLY_CLICK", function (e) {
                    param.filters.adType = [];
                    $.each(e.originalEvent.data.checkedArr, function (index, item) {
                    	param.filters.adType.push(item.value);
                    });
                    if (param.filters.adType.length==0) {
                    	param.groups = _.without(param.groups, "adType");
                    } else {
                        param.groups = _.union(param.groups, ["adType"]);
                    }
                });

                //年龄段选择
                $("div.ndp-drop-wrapper[name=drop-age]").empty().drop({
                    type: 4,
                    data: [
                        "13-17",
                        "18-24",
                        "25-34",
                        "35-44",
                        "45-54",
                        "55-64",
                        "65+",
                        { id: "unknown", text: I18N.getText("ecReport", "unknown") }],
                    placeholder: I18N.getText("ecReport", "chooseAge")
                }).off("APPLY_CLICK").on("APPLY_CLICK", function (e) {
                    if ($("div.ndp-drop-wrapper[name=drop-age]").hasClass("disabled")) {
                        self.alert(I18N.getText('ecReport', 'conflict', I18N.getText('ecReport', 'age'), I18N.getText('ecReport', 'device'), I18N.getText('ecReport', 'placement'), I18N.getText('ecReport', 'productId')));
                        $("div.ndp-drop-wrapper[name=drop-age]").find("input").val("");
                        return false;
                    }
                    param.filters.age = [];
                    $.each(e.originalEvent.data.checkedArr, function (index, item) {
                    	param.filters.age.push(item.value);
                    });
                    if (param.filters.age.length==0) {
                    	param.groups = _.without(param.groups, "age");
                    } else {
                        param.groups = _.union(param.groups, ["age"]);
                    }
                    self.uiMutualExclusion();
                });
                //设备
                $("div.ndp-drop-wrapper[name=drop-device]").empty().drop({
                    type: 4,
                    data: [
                        { id: "desktop", text: I18N.getText("ecReport", "desktop") },
                        { id: "mobile", text: I18N.getText("ecReport", "mobile") },
                        { id: "tablet", text: I18N.getText("ecReport", "tablet") },
                        { id: "other", text: I18N.getText("ecReport", "other") }
                    ],
                    placeholder: I18N.getText("ecReport", "chooseDevice")
                }).off("APPLY_CLICK").on("APPLY_CLICK", function (e) {
                    if ($("div.ndp-drop-wrapper[name=drop-device]").hasClass("disabled")) {
                        self.alert(I18N.getText('ecReport', 'conflict', I18N.getText('ecReport', 'device'), I18N.getText('ecReport', 'age'), I18N.getText('ecReport', 'placement'), I18N.getText('ecReport', 'productId')));
                        $("div.ndp-drop-wrapper[name=drop-device]").find("input").val("");
                        return false;
                    }
                    param.filters.device = [];
                    $.each(e.originalEvent.data.checkedArr, function (index, item) {
                        param.filters.device.push(item.value);
                    })
                    if (param.filters.device.length==0) {
                    	param.groups = _.without(param.groups, "device");
                    } else {
                        param.groups = _.union(param.groups, ["device"]);
                    }
                    self.uiMutualExclusion();
                });
                //性别
                $("div.ndp-drop-wrapper[name=drop-gender]").empty().drop({
                    type: 4,
                    data: [
                        { id: "male", text: I18N.getText("ecReport", "male") },
                        { id: "female", text: I18N.getText("ecReport", "female") },
                        { id: "unknown", text: I18N.getText("ecReport", "unknown") }
                    ],
                    placeholder: I18N.getText("ecReport", "chooseGender")
                }).off("APPLY_CLICK").on("APPLY_CLICK", function (e) {
                    if ($("div.ndp-drop-wrapper[name=drop-gender]").hasClass("disabled")) {
                        self.alert(I18N.getText('ecReport', 'conflict', I18N.getText('ecReport', 'gender'), I18N.getText('ecReport', 'device'), I18N.getText('ecReport', 'placement'), I18N.getText('ecReport', 'productId')));
                        $("div.ndp-drop-wrapper[name=drop-gender]").find("input").val("");
                        return false;
                    }
                    var all = _.filter(e.originalEvent.data.checkedArr, function (i) {
                        return i.value == "all";
                    })[0];
                    param.filters.gender = [];
                    $.each(e.originalEvent.data.checkedArr, function (index, item) {
                        param.filters.gender.push(item.value);
                    })
                    if (param.filters.gender.length==0) {
                    	param.groups = _.without(param.groups, "gender");
                    } else {
                        param.groups = _.union(param.groups, ["gender"]);
                    }
                    self.uiMutualExclusion();
                });

                //分组条件， 选项在html里
                $('#drop-group-select2').select2({
                    placeholder: I18N.getText("ecReport", "chooseGroups")
                }).on('change', function () {
                    param.groups = ["day"]; //默认值
                    //处理界面
                    if (!_.isEmpty(param.filters.account)) {
                        param.groups.push("account");
                    }
                    if (!_.isEmpty(param.filters.adType)) {
                        param.groups.push("adType");
                    }
                    if (!_.isEmpty(param.filters.age)) {
                        param.groups.push("age");
                    }
                    if (!_.isEmpty(param.filters.device)) {
                        param.groups.push("device");
                    }
                    if (!_.isEmpty(param.filters.gender)) {
                        param.groups.push("gender");
                    }
                    param.groups = _.union(param.groups, $(this).val());
                    
                });

                $("#btnSearch").off("click").click(function (e) {
                    $('.summary').addClass('hidden');
                    //重置分页
                    param.cPage = 1;
                    pageNav.cPage = 1;
                    self.reqData(param);
                });

                $("#btnExport").off("click").click(function (e) {
                    //window.open(apiUrl + '/ecReport/export');
                    var pm = _.clone(param);
                    pm.cPage = 1;
                    pm.pSize = 1000;
                    console.log(pm)
                    self.exportData(pm);

                    //if (tableData) {
                    //    var csvData = _.map(tableData, function (d) {
                    //        $.each(d.fbData, function (i) {
                    //            var prefix = "fb."
                    //            d[prefix + i] = d.fbData[i];
                    //        });
                    //        $.each(d.gaData, function (i) {
                    //            var prefix = "ga."
                    //            d[prefix + i] = d.gaData[i];
                    //        });
                    //        var r = _.omit(d, "fbData", "gaData");
                    //        return r;
                    //    });
                    //    console.log(csvData);
                    //    self.JSONToCSVConvertor(csvData, "retargeting", true);
                    //} else {
                    //    self.alert( I18N.getText('ecReport','noDataExport'));
                    //}
                });

                this.initTable();
            },
            //初始化表格
            initTable: function (selector) {
                var self = this;
                var isFirstInit = true;
                if (_.isUndefined(selector)) {
                    selector = '[list-manager="report-list"]';
                } else {
                    $('#sectionReport').append('<table class="ndp-table" id="ecReportTable" list-manager=' + selector + '><thead></thead><tbody></tbody></table>');
                    selector = '[list-manager="' + selector + '"]';
                }
                $(selector + ' thead').html(self.getTh());
                $(selector).listManager('init', {
                    isRealTime: false
                    , supportSorting: true
                    , sizeData: [1, 10, 20, 30, 40, 50, 60]
                    , pageSize: pageNav.pSize
                    , pageQuery: {
                        name: 'listManager.pageQuery',
                        value: '这个属性可用于 分页事件带回当前列表查询需要的参数'
                    }
                    , supportAjaxPage: true		//是否支持配置列表ajxa分页[多列表两种状态都有时，统一配置为true,禁用的列表pageJson参数为空即可]
                    , pageCallback: function (q) {
                        if (isFirstInit) {
                            console.log("first init");
                            console.log(q);
                            isFirstInit = false;
                        } else {
                            pageNav.cPage = q.cPage;
                            pageNav.pSize = q.pSize;
                            param.cPage = pageNav.cPage;
                            param.pSize = pageNav.pSize;
                            self.reqData(param);
                        }
                    }
                }, function (query) {
                    console.log("------------------------");
                    console.log(query);
                    $(selector).listManager([{ 'resetTd': false, 'resetPageData': pageNav }]);
                });
                // self.adjustTableColumn();
            },
            clearTable: function () {
                //if (!localStorage.reportTableIndex) {
                //    //初始值
                //    localStorage.reportTableIndex = 1;
                //} else {
                //    //自增
                //    localStorage.reportTableIndex = Number(localStorage.reportTableIndex) + 1;
                //}
                $('.table-warp').remove();
                var selector = "report-list";
                return selector;
            },
            uiMutualExclusion: function () {
                if (!_.isEmpty(param.filters.device)) {
                	$("div.ndp-drop-wrapper[name=drop-age]").addClass("disabled");
                	$("div.ndp-drop-wrapper[name=drop-gender]").addClass("disabled");
                } else {
                	$("div.ndp-drop-wrapper[name=drop-age]").removeClass("disabled");
                	$("div.ndp-drop-wrapper[name=drop-gender]").removeClass("disabled");
                }
                if (!_.isEmpty(param.filters.age || !_.isEmpty(param.filters.gender))) {
                	$("div.ndp-drop-wrapper[name=drop-device]").addClass("disabled");
                } else {
                	$("div.ndp-drop-wrapper[name=drop-device]").removeClass("disabled");
                }

            },
            //检查分组条件互斥情况
            isMutualExclusion: function (group) {
                if (_.contains(group, "device")) {
                    if (_.contains(group, "age")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'device'), I18N.getText('ecReport', 'age')));
                        return true;
                    } else if (_.contains(group, "gender")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'device'), I18N.getText('ecReport', 'gender')));
                        return true;
                    }
                }
                if (_.contains(group, "placement")) {
                    if (_.contains(group, "age")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'placement'), I18N.getText('ecReport', 'age')));
                        return true;
                    }
                    if (_.contains(group, "gender")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'placement'), I18N.getText('ecReport', 'gender')));
                        return true;
                    }
                }
                if (_.contains(group, "productId")) {
                    if (_.contains(group, "age")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'productId'), I18N.getText('ecReport', 'age')));
                        return true;
                    }
                    if (_.contains(group, "gender")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'productId'), I18N.getText('ecReport', 'gender')));
                        return true;
                    }
                    if (_.contains(group, "device")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'productId'), I18N.getText('ecReport', 'device')));
                        return true;
                    }
                    if (_.contains(group, "placement")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'productId'), I18N.getText('ecReport', 'placement')));
                        return true;
                    }
                }
                if (_.contains(group, "country")) {
                    if (_.contains(group, "age")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'country'), I18N.getText('ecReport', 'age')));
                        return true;
                    }
                    if (_.contains(group, "gender")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'country'), I18N.getText('ecReport', 'gender')));
                        return true;
                    }
                    if (_.contains(group, "productId")) {
                        self.alert(I18N.getText('ecReport', 'conflictCheck', I18N.getText('ecReport', 'country'), I18N.getText('ecReport', 'productId')));
                        return true;
                    }
                }
            },
            alert: function (c, t) {
                if (!t) {
                    t = "TIPS";
                }
                showAlert({ title: t, content: c });
            },
            reqMenus: function () {
                reportBean.allWebSite(function (result) {
                    menus = result;
                    self.initView();
                }, function () {
                    self.alert("error");
                });
            },
            //请求数据
            reqData: function (p) {
                if (_.isEmpty(p.filters.webSite)) {
                    self.alert(I18N.getText('ecReport', 'requireWebSite'));
                    return false;
                }
                if (self.isMutualExclusion(param.groups)) {
                	//param.groups = [];
                    //$("#drop-group").find("input").val("");
                    return false;
                } 
                //参数中list去重
                p.groups = _.uniq(p.groups);
                _.map(p.filters, function (i) {
                    if (_.isArray(i)) {
                        return _.uniq(i);
                    } else {
                        return i;
                    }
                });
                reportBean.report(p, function (result) {
                    if (result.list && result.fbSummary) {
                        pageNav.tSize = result.fbSummary.count;
                        pageNav.tPage = parseInt(pageNav.tSize / pageNav.pSize);
                        if (pageNav.tSize % pageNav.pSize > 0) {
                            pageNav.tPage = pageNav.tPage + 1;
                        }
                        var selector = self.clearTable();
                        self.initTable(selector);
                        tableData = result.list;
                        self.rendererTable(result.list);
                        self.renderTableSummary(result.fbSummary, result.gaSummary);
                        self.adjustTableColumn();
                    } else {
                        self.alert(I18N.getText('ecReport', 'noData'));
                        self.clearTable();
                    }
                }, function () {
                    self.alert("error!");
                });
            },
            //导出数据
            exportData: function (p) {
                if (_.isEmpty(p.filters.webSite)) {
                    self.alert(I18N.getText('ecReport', 'requireWebSite'));
                    return false;
                }

                //参数中list去重
                p.groups = _.uniq(p.groups);
                _.map(p.filters, function (i) {
                    if (_.isArray(i)) {
                        return _.uniq(i);
                    } else {
                        return i;
                    }
                });
                var _thCache = new Array();
                var thList = $('#ecReportTable thead[class!="set-top"] th');
                var $v;
                $.each(thList, function (i, v) {
                    $v = $(v);
                    var $tempDom = $('.config-area li[th-name="' + v.getAttribute('th-name') + '"]', $('#ecReportTable').parents('.table-warp').eq(0));
                    if ($tempDom[0]) {
                        if ($tempDom.find('input[type="checkbox"]')[0]) {
                            if ($tempDom.find('input[type="checkbox"]').get(0).checked)
                                _thCache.push(v.getAttribute('th-name'));
                        }
                    }
                });
                p.ths = _thCache;
                window.open(apiUrl + '/ecReport/export?param=' + JSON.stringify(p));
            },
            //渲染广告账号
            rendererDropActs: function (acts) {
                //账号选择
                $("div.ndp-drop-wrapper[name=drop-acts]").empty().drop({
                    type: 4,
                    data: acts,
                    name: "acts",
                    placeholder: I18N.getText('ecReport', 'chooseAccounts')
                }).off("APPLY_CLICK").on("APPLY_CLICK", function (e) {
                    param.filters.account = [];
                    $.each(e.originalEvent.data.checkedArr, function (index, item) {
                        param.filters.account.push(item.value);
                    })
                    if(param.filters.account.length==0){
                    	param.groups = _.without(param.groups, "account");
                    }else{
                    	param.groups = _.union(param.groups,["account"]);
                    }
                    
                });
            },
            getTh: function () {
                return _.template($('#thTemplate').text())(param);
            },
            getTrTemplate: function () {
                var t = '';
                $(".ndp-table thead th").each(function () {
                    var f = $(this).attr('th-name');
                    if ($(this).attr('th-hide') == 'true') {
                        t = t + '<td name="' + f + '" class="hidden"></td>';
                    } else {
                        var d = f.replace("-", ".");
                        t = t + '<td name="' + f + '"><%= (data.' + d + ') %></td>';
                    }
                });
                return '<tr>' + t + '</tr>'
            },
            getTr: function (data, temp) {
                return _.template(temp, { variable: 'data' })(data);
            },
            //渲染表格
            rendererTable: function (list) {
                _.map(list, function (item) {
                    item.week = moment(item.day).format("dddd");
                    item.spend = (item.spend / 100).toFixed(2) + "$";
                    if (_.isEmpty(item.fbData)) {
                        item.fbData = {};
                    } else {
                        item.fbData.cpc = (item.fbData.cpc / 100).toFixed(2) + "$";
                        item.fbData.checkoutCR = (item.fbData.checkoutCR * 100).toFixed(2) + "%";
                        if (item.fbData.checkout == 0) {
                            item.fbData.cps = "-";
                        } else {
                            item.fbData.cps = (item.fbData.cps / 100).toFixed(2) + "$";
                        }
                        item.fbData.salesAmount = (item.fbData.salesAmount / 100).toFixed(2) + "$";
                        item.fbData.roi = (item.fbData.roi).toFixed(2);
                    }
                    if (_.isEmpty(item.gaData)) {
                        item.gaData = {};
                    } else {
                        item.gaData.cpc = (item.gaData.cpc / 100).toFixed(2);
                        item.gaData.cartCR = (item.gaData.cartCR * 100).toFixed(2) + "%";
                        item.gaData.cr = (item.gaData.cr * 100).toFixed(2) + "%";
                        item.gaData.cpa = (item.gaData.cpa / 100).toFixed(2) + "$";
                        item.gaData.orderAmount = (item.gaData.orderAmount / 100).toFixed(2) + "$";
                        item.gaData.orderPrice = (item.gaData.orderPrice / 100).toFixed(2) + "$";
                        item.gaData.roi = (item.gaData.roi).toFixed(2);
                    }
                    var temp = self.getTrTemplate();
                    $("table tbody").append(self.getTr(item, temp));
                })
            },
            /**
             *
             * @param summary
             */
            renderTableSummary: function (summary, gaSummary) {

                var footerHtml = '';
                if (summary && (summary.count + '').length > 0) {
                    footerHtml += '<div class="summary-div"><b>' + I18N.getText('ecReport', 'fbSummary') + '</b>&nbsp;&nbsp;';
                    footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'salesAmount') + ' : ' + (' $ ' + kit.cent_to_dollar(summary.salesAmount)) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    if ((summary.spent + '').length > 0) { //成本
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'spend') + ' : ' + (' $ ' + kit.cent_to_dollar(summary.spend)) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((summary.cpc + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'cpc') + ' : ' + (' $ ' + kit.cent_to_dollar(summary.cpc)) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((summary.cps + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'cps') + ' : ' + (' $ ' + kit.cent_to_dollar(summary.cps)) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((summary.checkoutCR + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'checkoutCR') + ' : ' + (summary.checkoutCR * 100).toFixed(2) + '%</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((summary.clicks + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'clicks') + ' : ' + summary.clicks + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((summary.impressions + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'impressions') + ' : ' + summary.impressions + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((summary.checkout + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'checkout') + ' : ' + summary.checkout + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((summary.roi + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'roi') + ' : ' + (summary.roi>0?summary.roi.toFixed(2):summary.roi) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((summary.cart + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'cart') + ' : ' + summary.cart + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    footerHtml += '</div>';
                }
                if (gaSummary) {
                    footerHtml += '<div class="summary-div"><b>' + I18N.getText('ecReport', 'gaSummary') + '</b>&nbsp;&nbsp;';
                    if ((gaSummary.cpc + '').length > 0) {
                        footerHtml += '<span>' + I18N.getText('ecReport', 'cpc') + ' : ' + (' $ ' + kit.cent_to_dollar(gaSummary.cpc)) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((gaSummary.cpa + '').length > 0) {
                        footerHtml += '<span>' + I18N.getText('ecReport', 'cpa') + ' : ' + (' $ ' + kit.cent_to_dollar(gaSummary.cpa)) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((gaSummary.orderPrice + '').length > 0) {
                        footerHtml += '<span>' + I18N.getText('ecReport', 'orderPrice') + ' : ' + (' $ ' + kit.cent_to_dollar(gaSummary.orderPrice)) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((gaSummary.orderAmount + '').length > 0) {
                        footerHtml += '<span>' + I18N.getText('ecReport', 'orderAmount') + ' : ' + (' $ ' + kit.cent_to_dollar(gaSummary.orderAmount)) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((gaSummary.clicks + '').length > 0) {
                        footerHtml += '<span>' + I18N.getText('ecReport', 'clicks') + ' : ' + gaSummary.clicks + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((gaSummary.pays + '').length > 0) {
                        footerHtml += '<span>' + I18N.getText('ecReport', 'gaData-payS') + ' : ' + gaSummary.pays + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((gaSummary.roi + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'roi') + ' : ' + (gaSummary.roi>0?gaSummary.roi.toFixed(2):0) + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((gaSummary.cart + '').length > 0) {
                        footerHtml += '<span>' + I18N.getText('ecReport', 'cart') + ' : ' + gaSummary.cart + '</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((gaSummary.cartCR + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'gaData-cartR') + ' : ' + ((gaSummary.cartCR * 100)>0?(gaSummary.cartCR * 100).toFixed(2):0) + '%</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }
                    if ((gaSummary.cr + '').length > 0) {
                        footerHtml = footerHtml + '<span>' + I18N.getText('ecReport', 'cr') + ' : ' + ((gaSummary.cr * 100)>0?(gaSummary.cr * 100).toFixed(2):0) + '%</span> &nbsp;&nbsp;&nbsp;&nbsp;';
                    }

                    footerHtml += '</div>';
                }

                $("table tbody").append('<tr><td colspan="22">' + footerHtml + '</td></tr>');

                //if(footerHtml.length > 0) {
                //    $footer.html(footerHtml);
                //    $footer.width($('#sectionReport').width()+13);
                //    $footer.removeClass('hidden');
                //} else {
                //    $footer.addClass('hidden');
                //}
            },
            /**
             * 调整列的显示和隐藏
             */
            adjustTableColumn: function () {
                var $table = $('#ecReportTable');
                var $listManager = $table.listManager('getListManager')

                //先根据表格本身缓存中的配置,将需要隐藏的隐藏起来
                var key = $table.attr('list-manager') + '-' + $table.find('thead th').length;
                var tableCache = localStorage.getItem(key);
                if (tableCache) {
                    var tableConfig = JSON.parse(tableCache);
                    _.each(tableConfig.th, function (v, i) {
                        if ((v.isShow+'') == 'true') {
                            $listManager.showTh('[th-name="' + v.th_name + '"]');
                        } else {
                            $listManager.hideTh('[th-name="' + v.th_name + '"]');
                        }
                    });
                }

                //再将条件查询中不需要显示的隐藏起来
                $table.find('thead th[th-hide]').each(function () {
                    var tName = $(this).attr('th-name');
                    if ($(this).attr('th-hide') == 'true') {
                        $listManager.hideTh('[th-name="' + tName + '"]');
                        $('.config-list li[th-name="' + tName + '"]').addClass('hidden');
                    } else {
                        $listManager.showTh('[th-name="' + tName + '"]');
                    }
                });

            }
        };
    });
